package com.ops.chirpit;



import oauth.signpost.basic.DefaultOAuthProvider;
import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer;
import twitter4j.auth.AccessToken;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;

public class Preferences extends PreferenceActivity {
	static Context context;
	protected CommonsHttpOAuthConsumer httpOauthConsumer;
	protected DefaultOAuthProvider httpOauthprovider;
	public final static String consumerKey = "cOmJnUixYm6ApJRYAJXyMQ";
	public final static String consumerSecret = "Gwc1304Gs8Q8IgirASUns7QET2XBRzpjZYhVM9Ydlw";
	public static AccessToken a;
	private final static String CALLBACKURL = "tw://twit";
	private static String authUrl;
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    addPreferencesFromResource(R.xml.preferences);
	    //Preference twPref = (Preference) findPreference("Twitter");
	    OnPreferenceClickListener addAccountPref = new OnPreferenceClickListener() {
             public boolean onPreferenceClick(Preference preference) {
                 //open browser or intent here
            	 Intent intent = new Intent();
            	 intent.setAction("ACTION_VIEW")
            	 	.setClass(Preferences.this, AuthActivity.class)
            	 	.setData(Uri.parse(preference.getKey()));
            	 startActivityForResult(intent, ChirpItActivity.ADD_ACCOUNT);
            	 return false;
             }
         };
	}
	
	public static SharedPreferences getSharedPreferences (Context ctxt) {
		return ctxt.getSharedPreferences(ChirpItActivity.PREFS_NAME, 0);
	}
	
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
	      if (resultCode == RESULT_OK) {
	          if (requestCode == ChirpItActivity.ADD_ACCOUNT) {
	      		Intent intent = new Intent(Preferences.this, ChirpItActivity.class);
	          	intent.putExtra("ACTION", "ADD_ACCOUNT");
	          	setResult(RESULT_OK, intent);
	          	finish();
	          }
	      }
	  }

}